* Figure 2 Mean outcome variables by village-year treatment status
* Sample used to study investments and agricultural outcomes
* Last Updated, Niriksha Shetty 03/31/206

clear
clear mata
clear matrix
set maxvar 20000
set more off

pwd
cap cd c(`pwd')

estimates clear

use "../dta/reduced-form-master.dta", clear

*Using balanced panel
keep if bal_panel3==1

rename fraction_hy HY
rename fraction_cashcrop cashcrop

* Easier labels for graphs
lab var cost_k_w1_real "Total agricultural costs (INR)"
lab var profit_k_w1_real "Total agricultural profits (INR)"
lab var kval_w1_real "Total agricultural revenues (INR)"
lab var fin_costs_real "Total insurance costs (INR)"
lab var fin_revenues_real "Total insurance revenues (INR)"
lab var totalcosts_w1_real "Total costs (INR)"
lab var totalrevenues_w1_real "Total revenues (INR)"
lab var totalprofit_w1_real "Total profit (INR)"
lab var HY "Fraction of HYV crops"
lab var cashcrop "Fraction of cash-crops"
lab var plotsize_ha "Area cultivated (in hectares)"

// Gen averages
foreach var of varlist cost_k_w1_real kval_w1_real profit_k_w1_real fin_costs_real fin_revenues_real totalcosts_w1_real totalrevenues_w1_real totalprofit_w1_real HY cashcrop plotsize_ha {
bys mkt_year: egen avg_`var'_To=mean(`var') if originaltvillage==1 & surveyed 
bys mkt_year: egen avg_`var'_Tn=mean(`var') if firstt_2007 & surveyed // exclude villages added wave 4 & 5
bys mkt_year: egen avg_`var'_C=mean(`var') if Tvillage==0 & surveyed

lab var avg_`var'_To "Treatment Group 1"
lab var avg_`var'_Tn "Treatment Group 2"
lab var avg_`var'_C "Control Group"  
}

foreach var in cost_k_w1_real kval_w1_real profit_k_w1_real fin_costs_real fin_revenues_real totalcosts_w1_real totalrevenues_w1_real totalprofit_w1_real HY cashcrop plotsize_ha{ 
local l`var':variable label `var'
twoway connected  avg_`var'_To avg_`var'_Tn avg_`var'_C mkt_year, title("`l`var''", size(s)) ylabel(,angle (30)) xlabel(2005(2)2013) xtitle("") graphregion(color(white)) plotregion(icolor(white)) msymbol(T D O)
graph save avg_`var', replace
graph export "../output/graphs/avg_`var'.emf", replace
}

grc1leg avg_cost_k_w1_real.gph avg_kval_w1_real.gph avg_profit_k_w1_real.gph avg_fin_costs_real.gph avg_fin_revenues_real.gph avg_totalcosts_w1_real.gph avg_totalrevenues_w1_real.gph avg_totalprofit_w1_real.gph avg_HY.gph avg_cashcrop.gph avg_plotsize_ha.gph, graphregion(color(white) lwidth(large)) plotregion(icolor(white)) 
graph export "../output/graphs/f2.emf", replace


